<#import "add_base.ftl" as add/>
<@add.html>
<#include "add_mb.ftl">


        <tr>
          <th>储值卡卡号</th>
          <td colspan="3"><input type="text" name="giftCardCode" value="" onchange="chkGiftCard(this);" style="width:200px;" maxlength="19">
            <input class="opwin" value="..." onclick="selGiftCard();" type="button"></td>
        </tr>
        <tr>
          <th>储值卡类型</th>
          <td><input type="text" name="giftCardType" value="" class="disable" readonly></td>
          <th>金额</th>
          <td><input type="text" name="giftCardAmount" value="" class="disable" readonly></td>
        </tr>

<script type="text/javascript">
  var _contract = null;
  function fillData(mc) {
    if(mc.giftCardCode!="") {
      window.alert("该合同已经赠送过储值卡");
      clmbc();
      return;
    }
    _contract = mc;
    var fm = getEl("fm_input");
    fm.giftCardCode.value = "";
    fm.giftCardType.value = "";
    fm.giftCardAmount.value = "";
  }
  function clearData() {
    _contract = null;
    var fm = getEl("fm_input");
    fm.giftCardCode.value = "";
    fm.giftCardType.value = "";
    fm.giftCardAmount.value = "";
  }

  function selGiftCard() {
    if(_contract==null) {
      window.alert("请先输入合同号");
      return;
    }
    openWin("getGiftCardList?shopCode="+_contract.shopCode, 500, 400);
  }
  function selGiftCardOk(vv, ct, cm) {
    var fm = getEl("fm_input");
    fm.giftCardCode.value = vv;
    fm.giftCardType.value = ct;
    fm.giftCardAmount.value = cm;
  }
  function chkGiftCard(ipt) {
    if(ipt.value!="") {
      if(_contract==null) {
        window.alert("请先输入合同号");
        return;
      }
      getJson("getGiftCardNew?cardCode="+ipt.value+"&shopCode="+_contract.shopCode, function(data){
        if(data.ret) {
          var fm = getEl("fm_input");
          fm.giftCardCode.value = data.data.cardCode;
          fm.giftCardType.value = data.data.cardTypeName;
          fm.giftCardAmount.value = data.data.cardAmount;
        } else {
          window.alert(data.msg);
        }
      });
    }
  }
</script>
</@add.html>